package behavior.observe;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lie on 2017/11/2.
 * 模拟微信公众号
 */
public class WeChatSubject implements Subject{
    private final List<Observer> wxUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        wxUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        wxUserList.remove(observer);
    }

    @Override
    public void notify(String msg) {
        for (Observer  observer: wxUserList) {
            observer.update(msg);
        }
    }
}
